package com.appwoo.txtws.activity;

import android.app.Dialog;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.content.res.Resources;
import android.os.Bundle;
import android.util.DisplayMetrics;
import android.view.Display;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.GridView;
import android.widget.LinearLayout.LayoutParams;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.RadioGroup.OnCheckedChangeListener;
import android.widget.TextView;
import com.appwoo.txtws.adapter.WinInTestAdapter;
import com.appwoo.txtws.bean.BookGradeBean;
import com.appwoo.txtws.bean.BookSubjectBean;
import com.appwoo.txtws.component.DBHelper;
import java.util.ArrayList;
import java.util.Iterator;

public class WinInTestActivity extends BookActivity
  implements View.OnClickListener, RadioGroup.OnCheckedChangeListener
{
  public static final String BOOKSTORE_LEVEL_TYPE_WIN_IN_TEST_JUNIOR = "winInTestJunior";
  public static final String BOOKSTORE_LEVEL_TYPE_WIN_IN_TEST_SENIOR = "winInTestSenior";
  public static final int BOOKTYPE_WIN_IN_TEST_JUNIOR = 1;
  public static final int BOOKTYPE_WIN_IN_TEST_SENIOR = 1;
  public static final String SP_KEY_BOOK_SUBJECT_WIN_IN_TEST = "bookSubjectWinInTest";
  private int bookGradeBeanJuniorId;
  private int bookGradeBeanSeniorId;
  private ArrayList<BookSubjectBean> bookSubjects = new ArrayList();
  private Dialog exitConfirmClickDialog;
  private View.OnClickListener exitConfirmDialogNoOnClickListener = new View.OnClickListener()
  {
    public void onClick(View paramAnonymousView)
    {
      WinInTestActivity.this.exitConfirmClickDialog.dismiss();
    }
  };
  private View.OnClickListener exitConfirmDialogYesOnClickListener = new View.OnClickListener()
  {
    public void onClick(View paramAnonymousView)
    {
      WinInTestActivity.this.exitConfirmClickDialog.dismiss();
      WinInTestActivity.this.finish();
    }
  };
  private LayoutInflater inflater;
  private WinInTestAdapter mAdapter;
  private DBHelper mDBHelper;
  private GridView mGvWinInTestSubject;
  private RadioButton mRbWinInTestHeaderJuniorHightTest;
  private RadioGroup mRgWinInTestheader;

  private void findView()
  {
    this.mRbWinInTestHeaderJuniorHightTest = ((RadioButton)findViewById(2131493655));
    this.mGvWinInTestSubject = ((GridView)findViewById(2131493657));
    this.mRgWinInTestheader = ((RadioGroup)findViewById(2131493654));
    this.inflater = ((LayoutInflater)getSystemService("layout_inflater"));
  }

  private ArrayList<BookSubjectBean> getJuniorBookSubjectList()
  {
    new ArrayList();
    return this.mDBHelper.getBookSubjectBeanList(this.bookGradeBeanJuniorId);
  }

  private ArrayList<BookSubjectBean> getSeniorBookSubjectList()
  {
    new ArrayList();
    return this.mDBHelper.getBookSubjectBeanList(this.bookGradeBeanSeniorId);
  }

  private void init()
  {
    this.mDBHelper = new DBHelper(this);
    SharedPreferences localSharedPreferences = getSharedPreferences("book", 0);
    String str = localSharedPreferences.getString("bookSubjectWinInTest", null);
    if ((str == null) || ("".equals(str)))
    {
      writeData();
      SharedPreferences.Editor localEditor = localSharedPreferences.edit();
      localEditor.putString("bookSubjectWinInTest", "writed");
      localEditor.commit();
    }
    BookGradeBean localBookGradeBean1 = this.mDBHelper.getBookGradeBeanByGradename("中考");
    if (localBookGradeBean1 != null)
      this.bookGradeBeanJuniorId = localBookGradeBean1.getGradeId();
    BookGradeBean localBookGradeBean2 = this.mDBHelper.getBookGradeBeanByGradename("高考");
    if (localBookGradeBean2 != null)
      this.bookGradeBeanSeniorId = localBookGradeBean2.getGradeId();
  }

  private void setView()
  {
    this.mRbWinInTestHeaderJuniorHightTest.setChecked(true);
    this.mRgWinInTestheader.setOnCheckedChangeListener(this);
    DisplayMetrics localDisplayMetrics = new DisplayMetrics();
    getWindowManager().getDefaultDisplay().getMetrics(localDisplayMetrics);
    this.mAdapter = new WinInTestAdapter(this, this.bookSubjects, localDisplayMetrics.widthPixels / 5);
    this.mGvWinInTestSubject.setAdapter(this.mAdapter);
  }

  private void showSubject()
  {
    if (this.mRgWinInTestheader.getCheckedRadioButtonId() == 2131493655)
    {
      this.bookSubjects = getJuniorBookSubjectList();
      if (this.mAdapter != null)
        this.mAdapter.setBookGrade(this.bookGradeBeanJuniorId);
    }
    while (true)
    {
      if (this.mAdapter != null)
      {
        this.mAdapter.setData(this.bookSubjects);
        this.mAdapter.notifyDataSetChanged();
      }
      return;
      this.bookSubjects = getSeniorBookSubjectList();
      if (this.mAdapter != null)
        this.mAdapter.setBookGrade(this.bookGradeBeanSeniorId);
    }
  }

  private void writeData()
  {
    String[] arrayOfString = { "语文", "数学", "英语" };
    ArrayList localArrayList1 = this.mDBHelper.getBookSubjectBeanList(-1);
    BookGradeBean localBookGradeBean1 = this.mDBHelper.getBookGradeBeanByGradename("中考");
    String str1 = "@" + localBookGradeBean1.getGradeId() + "@";
    Iterator localIterator1 = localArrayList1.iterator();
    String str3;
    Iterator localIterator2;
    if (!localIterator1.hasNext())
    {
      ArrayList localArrayList2 = this.mDBHelper.getBookSubjectBeanList(-1);
      BookGradeBean localBookGradeBean2 = this.mDBHelper.getBookGradeBeanByGradename("高考");
      str3 = "@" + localBookGradeBean2.getGradeId() + "@";
      localIterator2 = localArrayList2.iterator();
      if (localIterator2.hasNext());
    }
    else
    {
      BookSubjectBean localBookSubjectBean1 = (BookSubjectBean)localIterator1.next();
      int i = arrayOfString.length;
      int j = 0;
      label166: if (j < i)
        if (arrayOfString[j].equals(localBookSubjectBean1.getName()))
        {
          String str2 = localBookSubjectBean1.getAscription();
          if ((str2 == null) || ("".equals(str2)))
            break label262;
          if (str2.indexOf(str1) == -1)
            localBookSubjectBean1.setAscription(str2 + str1);
        }
      while (true)
      {
        this.mDBHelper.updateBookSubjectBean(localBookSubjectBean1);
        j++;
        break label166;
        break;
        label262: localBookSubjectBean1.setAscription(str1);
      }
    }
    BookSubjectBean localBookSubjectBean2 = (BookSubjectBean)localIterator2.next();
    int k = arrayOfString.length;
    int m = 0;
    label291: if (m < k)
      if (arrayOfString[m].equals(localBookSubjectBean2.getName()))
      {
        String str4 = localBookSubjectBean2.getAscription();
        if ((str4 == null) || ("".equals(str4)))
          break label387;
        if (str4.indexOf(str3) == -1)
          localBookSubjectBean2.setAscription(str4 + str3);
      }
    while (true)
    {
      this.mDBHelper.updateBookSubjectBean(localBookSubjectBean2);
      m++;
      break label291;
      break;
      label387: localBookSubjectBean2.setAscription(str3);
    }
  }

  protected void backKeyCallBack()
  {
    super.backKeyCallBack();
    if ((BookstoreActivity.downloadTasks != null) && (!BookstoreActivity.downloadTasks.isEmpty()))
    {
      showExitClickDialog();
      return;
    }
    finish();
  }

  public void onCheckedChanged(RadioGroup paramRadioGroup, int paramInt)
  {
    showSubject();
  }

  public void onClick(View paramView)
  {
    paramView.getId();
  }

  protected void onCreate(Bundle paramBundle)
  {
    super.onCreate(paramBundle);
    setContentView(2130903235);
    init();
    findView();
    setView();
  }

  protected void onDestroy()
  {
    BookstoreActivity.cancleAllAsyncTask();
    super.onDestroy();
  }

  protected void onResume()
  {
    super.onResume();
    showSubject();
  }

  public void showExitClickDialog()
  {
    View localView = this.inflater.inflate(2130903050, null);
    ((TextView)localView.findViewById(2131492930)).setText(getString(2131428187));
    ((TextView)localView.findViewById(2131492931)).setText(getResources().getString(2131428199));
    Button localButton1 = (Button)localView.findViewById(2131492933);
    Button localButton2 = (Button)localView.findViewById(2131492934);
    localButton1.setOnClickListener(this.exitConfirmDialogYesOnClickListener);
    localButton2.setOnClickListener(this.exitConfirmDialogNoOnClickListener);
    this.exitConfirmClickDialog = new Dialog(this, 2131361833);
    this.exitConfirmClickDialog.addContentView(localView, new LinearLayout.LayoutParams(-2, -2));
    this.exitConfirmClickDialog.setCanceledOnTouchOutside(true);
    this.exitConfirmClickDialog.show();
  }
}

/* Location:           C:\Documents and Settings\Administrator\classes_dex2jar.jar
 * Qualified Name:     com.appwoo.txtws.activity.WinInTestActivity
 * JD-Core Version:    0.6.2
 */